/*
 * @Author: ailin
 * @Date: 2023-02-21 13:18:50
 * @LastEditors: ailin
 * @LastEditTime: 2023-07-27 09:23:54
 * @Description: file content
 * @FilePath: /pay_platform/src/request/loading.js
 */
// import { ElLoading } from 'element-plus'
import { showLoadingToast, closeToast } from "vant"
// loading函数
// 记录请求次数
let needLoadingRequestCount = 0
let loading
function startLoading() {
  // loading = ElLoading.service({
  //   lock: true,
  //   text: '加载中……',
  //   background: 'rgba(0, 0, 0, 0.5)',
  // });
  showLoadingToast({
    // message: "加载中...",
    forbidClick: true,
    duration: 0
  })
}
function endLoading() {
  // 延迟300ms，防止网速特快加载中画面一闪而过
  // setTimeout(function () {
  //   closeToast()
  // }, 300)
  closeToast()
}
// 打开loading
function showLoading() {
  if (needLoadingRequestCount === 0) {
    startLoading()
  }
  needLoadingRequestCount++
}
// 关闭loading
function hideLoading() {
  if (needLoadingRequestCount <= 0) return
  needLoadingRequestCount--
  if (needLoadingRequestCount === 0) {
    endLoading()
  }
}

export { showLoading, hideLoading }
